# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=python-lsp-server
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=1.12.2
pkgrel=1
pkgdesc='Python Language Server for the Language Server Protocol (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/python-lsp-server'
)
license=('spdx:MIT')
url='https://github.com/python-lsp/python-lsp-server'
depends=(
    "${MINGW_PACKAGE_PREFIX}-python"
    "${MINGW_PACKAGE_PREFIX}-python-jedi"
    "${MINGW_PACKAGE_PREFIX}-python-lsp-jsonrpc"
    "${MINGW_PACKAGE_PREFIX}-python-pluggy"
    "${MINGW_PACKAGE_PREFIX}-python-docstring-to-markdown"
    "${MINGW_PACKAGE_PREFIX}-python-ujson"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
options=(!strip)
source=(https://pypi.org/packages/source/${_realname::1}/${_realname//-/_}/${_realname//-/_}-${pkgver}.tar.gz
        0001-python-lsp-server-1.5.0-allow-newlest-depends.patch)
sha256sums=('fea039a36b3132774d0f803671184cf7dde0c688e7b924f23a6359a66094126d'
            'b344d82a4dd5ba6eb2f885b4f9dc0e6bc1878dc8f22e6af79f66ca491d1d765c')

prepare() {
  cd "${_realname//-/_}-${pkgver}"
  patch -p1 -i "${srcdir}"/0001-python-lsp-server-1.5.0-allow-newlest-depends.patch

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cp -r "${_realname//-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
